<link href="/admins/css/adminshare.css" rel="stylesheet" type="text/css" />
<link href="/admins/css/yundan.css" rel="stylesheet" type="text/css" />
<script type="text/javascript" src="/js/boxy/js/jquery.boxy.js"></script>
<link href="/js/boxy/css/boxy.css" media="screen" rel="stylesheet" type="text/css" >  
<script type="text/javascript">
    $(function(){
        window.alert = Boxy.alert;
        window.confirm = Boxy.confirm;
    });
</script>
<style>
    .editdetail table{border: #fff solid 1px;width: 99%;font-size: 16px;}
    .editdetail table td{height: 30px;border-bottom: #fff solid 1px;border-right: #fff solid 1px;padding-top: 5px;vertical-align: top;}
    .editdetail table textarea{width: 540px;height: 120px;margin:5px 0px 5px 10px;border: 1px solid #3197B5;font-size: 16px;padding: 5px;}
    .editdetail table .lefttd{text-align: right;padding-right: 10px;width: 100px;padding-top: 10px;}
    .editdetail table .righttd{width: 320px;}
    .editdetail table td *{font-size: 16px;margin-left: 10px;border: 1px solid #3197B5;padding: 5px;}
    #jobTimeMonth {border:none;width:90%;float: left;margin-left: 0px;padding: 0px;margin-top: 10px;}
    #jobTimeMonth .monthNo{border:none;padding-left: 1px;float:left;width: 70px;}
    #jobTimeMonth .monthCkNo{border: 1px solid #3197B5;width: 68px;padding-left: 1px;float:left;}
</style>
<div class="editdetail">
    <div class="ydbottom">
        <div class="chuku">
            <div class="lanmu">
                <h2>添加新任务</h2>
            </div>
            <div>
                <form action="" method="post" id="editJobDetail">
                <table>
                    <tr>
                        <td class="lefttd">任务名称：<input type="hidden" id="jobId" name="jobId" value="" /></td>
                        <td colspan="3" class="righttd"><input type="text" id="jobName" name="jobName" value="" style="width:540px;"/></td>
                    </tr>
                    <tr>
                        <td class="lefttd">任务描述：</td>
                        <td colspan="3" class="righttd"><textarea id="jobDescription" name="jobDescription" ></textarea></td>
                    </tr>
                    <tr>
                        <td class="lefttd">是否启用：</td>
                        <td class="righttd"><select id="jobDisable" name="jobDisable">
                            <?php foreach ($this->jobDisableAll as $disableKey => $disableVal) { ?>
                                <option value="<?php echo $disableKey;?>" ><?php echo $disableVal;?></option>
                            <?php } ?>
                            </select></td>
                        <td class="lefttd">任务类型：</td>
                        <td><select id="jobType" name="jobType">
                            <?php foreach ($this->jobTypeAll as $typeKey => $typeVal) { ?>
                                <option value="<?php echo $typeKey;?>"><?php echo $typeVal;?></option>
                            <?php } ?>
                            </select></td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行内容：</td>
                        <td colspan="3" class="righttd"><textarea id="jobContent" name="jobContent" ></textarea></td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行类型：</td>
                        <td colspan="3" class="righttd">
                            <?php foreach ($this->jobExecuteAll as $executeKey => $executeVal) { ?>
                            <div style="margin-left: 0px;width: 100px;float: left;border: none;">
                                <input type="radio" id="jobExecute<?php echo $executeKey;?>" name="jobExecute" value="<?php echo $executeKey;?>" style="border: 1px solid #3197B5;margin-right: 5px;" <?php echo $executeKey==Application_Model_Job::Execute_EveryDay?"checked":"";?>/><?php echo $executeVal;?>
                            </div>
                            <?php } ?>
                        </td>
                    </tr>
                    <tr>
                        <td class="lefttd">执行时间：</td>
                        <td colspan="3" class="righttd">
                            <div id="jobtime" style="border:none;margin-left: -5px;width: 80px;float: left;">
                                <select id="jobTime" name="jobTime">
                                    <option value="-1">循环</option>
                                    <?php 
                                        $arrRunDate = explode(",", $this->jobItem->dateValue);
                                        for($i=0;$i<24;$i++){
                                            $html = "<option ";
                                            $html .= "value='".$i."'>".($i<10?"0$i":$i).":00</option>";
                                            echo $html;
                                        }
                                    ?>
                                </select>
                            </div>
                            <div id="jobfortime"  style="border:none;width: 500px;float: left;height: 40px;">
                                请输入任务循环执行间隔时间：<input type="text" id="fortime" name="fortime" value="" onkeyup="value=value.replace(/[^\d]/g,'')"/></div>
                            <div id="jobTimeWeek" style="border:none;width:90%;float: left;margin-left: 0px;padding: 0px;display:none">
                                <label style="border:none;margin-left: 0px;padding: 0px;">
                                    <input id="dateValue1" name="dateValueW[]" type="checkbox" value="1" />&nbsp;&nbsp;周一</label> 
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue2" name="dateValueW[]" type="checkbox" value="2" />&nbsp;&nbsp;周二</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue3" name="dateValueW[]" type="checkbox" value="3" />&nbsp;&nbsp;周三</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue4" name="dateValueW[]" type="checkbox" value="4" />&nbsp;&nbsp;周四</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue5" name="dateValueW[]" type="checkbox" value="5" />&nbsp;&nbsp;周五</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue6" name="dateValueW[]" type="checkbox" value="6" />&nbsp;&nbsp;周六</label>
                                <label style="margin-left: 15px;border:none;">
                                    <input id="dateValue0" name="dateValueW[]" type="checkbox" value="0" />&nbsp;&nbsp;周日</label>
                            </div>
                            <div id="jobTimeMonth" style="display:none;">
                                <?php 
                                    for($j=1;$j<32;$j++){
                                        $html = '<div class="monthNo"><input id="dateValue'.$j.'" name="dateValueM[]" type="checkbox" value="'.$j.'" ';
                                        $html .= " />&nbsp;&nbsp;".($j<10?"0$j":$j)."号</div>";
                                        $html .= $j==16?"<div style='border:none;width:99%;float:left;height: 1px;'></div>":"";
                                        
                                        echo $html;
                                    }
                                ?>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td class="lefttd"></td>
                        <td colspan="3" class="righttd">
                            <a class="anvbotton5 subEdit" href="javascript:void(0)" style="font-size: 16px;margin-left: 0px;border: none;padding: 0px;"><span style="margin-left: 0px;border: none;padding: 0 25px;">确认</span></a>
                            <a class="anvbotton4 reEdit" href="javascript:void(0)" style="font-size: 16px;border: none;padding: 0px;"><span style="margin-left: 0px;border: none;padding: 0 25px;">取消</span></a>
                        </td>
                    </tr>
                </table>
            </form>
            </div> 
        </div>
    </div>
</div>
<script>
$(function(){
    $("input[type='checkbox']").each(function(index,item){
        if($(item).attr("checked")){
            $(item).parent("div").addClass("monthCkNo");
            $(item).parent("div").removeClass("monthNo");
        }
        $(item).click(function(){
            if($(this).attr("checked")){
                $(this).parent("div").addClass("monthCkNo");
                $(this).parent("div").removeClass("monthNo");
            } else {
                $(this).parent("div").removeClass("monthCkNo");
                $(this).parent("div").addClass("monthNo");
            }
        });
    });
    $("input[type='radio'][name='jobExecute']").click(function(){
        var jobExecute = $(this).val();
        if(jobExecute == <?php echo Application_Model_Job::Execute_Week;?>){
            $("#jobTimeWeek").show();
            $("#jobTimeMonth").hide();
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Month;?>){
            $("#jobTimeWeek").hide();
            $("#jobTimeMonth").show();
            return ;
        }
        $("#jobTimeWeek").hide();
        $("#jobTimeMonth").hide();
        return ;
    });
});
$(function(){

    $(".reEdit").click(function(){
        location.href = document.referrer;
    });
    $(".subEdit").click(function(){
        var jobName = $("#jobName").val();
        var jobDescription = $("#jobDescription").val();
        var jobContent = $("#jobContent").val();
        var jobTime = $("#jobTime").val();
        var fortime = $("#fortime").val();
        var jobExecute = $("input[type='radio'][name='jobExecute']:checked").val();
        var dateValueW = $("input[type='checkbox'][name='dateValueW[]']:checked").length;
        var dateValueM = $("input[type='checkbox'][name='dateValueM[]']:checked").length;
        if(jobName == ""){
            alert("任务名称不能为空");
            return ;
        }
        if(jobDescription == ""){
            alert("任务描述不能为空");
            return ;
        }
        if(jobContent == ""){
            alert("执行内容不能为空");
            return ;
        }
        if(jobTime == <?php echo Application_Model_Job::Execute_ForTime;?> && fortime == ""){
            alert("循环时间不能为空");
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Week;?> && dateValueW == 0){
            alert("每周运行的日期不能为空");
            return ;
        }
        if(jobExecute == <?php echo Application_Model_Job::Execute_Month;?> && dateValueM == 0){
            alert("每月运行的日期不能为空");
            return ;
        }
        $("#editJobDetail").submit();
    });
});
</script>
